package com.distribution.common.web.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author test
 * @date 2022年01月04日 14:22
 */

@Component
public class JwtTokenUserDetailsService implements UserDetailsService {
    @Autowired
    private LoginService loginService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SecurityUser securityUser = loginService.loadByUsername(username);

        if(Objects.isNull(securityUser)){
            throw new UsernameNotFoundException("用户不存在");
        }

        return securityUser;
    }
}
